home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / FDEDISP3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  4.0 KB  |  143 lines

  1. /* fdedisp.c  file - enhance display_page function  */
  2. #include "stdio.h"
  3. #include "cminor.h"
  4. #include "fdparm.h"
  5. #include "scn.h"
  6.  
  7. extern    char  filename[]  ;
  8. extern    long  filesize      ;        /* size of file in bytes  */
  9. extern    long  top_of_page ;        /* file position of top of page */
  10.  
  11. /* special symbols to represent CR, LF, CTL-Z & other ctl chars  */
  12. #define    PRT_CR    20
  13. #define    PRT_LF    25
  14. #define    PRT_CTLZ    17
  15. #define    PRT_OTHER    22
  16. #define    ASC_CTLZ    26
  17.  
  18. int  row    ;                /* current line of page */
  19. long start  ;
  20. SCN_DATA sc ;
  21.  
  22. int  disp_page()
  23.   {
  24.      char  block[ LINE_SIZE ]  ;
  25.      int   nbytes  ;
  26.      int   i  ;             /* index for loops  */
  27.      int   srow , scol    ;
  28.      char  s[81]  ;
  29.  
  30.      vid_dlr_scn(0,24)    ;
  31.      scr_pos(&sc,0,0)  ;        /* set screen write pos.  */
  32.                     /* write border line of dashes    */
  33.      move_to(top_of_page)  ;        /* start at top of the page  */
  34.                     /* write a header line    */
  35.      sprintf(s," FILE - %s    POSITION - %1d    FILE SIZE - %1d ",
  36.      filename, top_of_page, filesize )    ;
  37.      scn_ws(s,&sc)  ;
  38.      scn_pos(&sc,1,0)  ;
  39.      for( i=1 ; i<=80 ; i=i+1 )
  40.     {  scn_ws('-',&sc) ;  }
  41.      /* get chars from file until we've written (PAGE_SIZE) lines */
  42.      /* or we've reached the end of the file  */
  43.      row = 1 ;                /* starting row values    */
  44.      start = top_of_page  ;
  45.      while( row <= PAGE_SIZE )
  46.     {  nbytes = read_line(block,LINE_SIZE)    ;
  47.        if( nbytes <= 0 )
  48.           break  ;
  49.        scn_pos(&sc,row+1,0)  ;
  50.        prtline(block,nbytes)  ;
  51.        start = start + nbytes  ;
  52.        row = row + 1  ;
  53.     }
  54.                     /* write border line of dashes */
  55.      scn_pos(&sc,18,0)    ;        /* set screen write pos. */
  56.                     /* write border line of dashes */
  57.      for( i=1 ; i <=80 ; i=i+1 )
  58.     { scn_wc('-',&sc) ;  }
  59.      scn_pos(19,0)  ;
  60.      vid_set_cur(19,0)    ;
  61.   }
  62. char hex[] = "0123456789ABCDEF"  ;
  63.  
  64. int  prtline(block,nbytes)        /* prints one line  */
  65.   char    block[]  ;
  66.   int    nbytes    ;
  67.   {
  68.      int   i  ;
  69.      int   t  ;
  70.      char  s[81]  ;
  71.  
  72.      sprintf(s,"%81d  |  ",start) ;      /* print file pos.  */
  73.      scn_ws(s,sc)  ;
  74.  
  75.      for( i=1 ; i< LINE_SIZE ; i=i+1 )    /*print bytes of Hex. */
  76.     {  if( i < nbytes )
  77.           {  t = (block[i] >> 4 ) & 0xf ;
  78.          scn_wc(hex[t] ,&sc )  ;
  79.          t = block[i] & 0xf  ;
  80.          scn_wc( hex[t] , &sc )  ;
  81.          scn_wc( ' ' , &sc )  ;
  82.           }
  83.        else  scn_ws("   ",&sc) ;    /* out of data - fill in  */
  84.     }
  85.  
  86.      scn_ws("| ", &sc)  ;
  87.  
  88.      for( i=0 ; i<nbytes ; i=i+1 )    /* display in ASCII form  */
  89.     {  disp_char( tochar(block[i]) ) ; }
  90.   }
  91.  
  92. int disp_char(c)            /* display one char in ASCII */
  93.   int    c  ;                /* value of char to display  */
  94.   {
  95.      /* classify the character and handle accordingly */
  96.  
  97.      if( isgraphic(c))
  98.     ;                /* ASCII graphic - just display  */
  99.      else if( c == '\n' )
  100.     c = PRT_LF  ;            /* newline (LF) - display symbol */
  101.      else if( c == '\r' )
  102.     c = PRT_CR  ;            /* Carr. Return - display symbol */
  103.      else if( c == ASC_CTLZ )
  104.     c = PRT_CTLZ  ;         /* CTL-Z - display symbol  */
  105.      else c = PRT_OTHER  ;        /* other char - display symbol    */
  106.  
  107.      scn_wc(c , &sc)  ;
  108.   }
  109.  
  110.  
  111. int  prompt()                /* display prompts  */
  112.   {
  113.   #define  UP_A  24            /* display up arrow  */
  114.   #define  DN_A  25            /* display down arrow */
  115.      char  s[81]  ;
  116.  
  117.      scn_pos( &sc , 20 , 0 )  ;
  118.      scn_ws(  "         Type one of these Input Commands" , & sc ) ;
  119.      scn_pos( &sc , 21 , 0 )  ;
  120.      scn_ws(  " HOME  = First Page      " , & sc) ;
  121.      sprintf(s,    "  %c   = Previous Line " , UP_A)  ;
  122.      scn_ws( s , & sc )  ;
  123.      scn_ws(     "PG UP = Previous Page " , & sc )  ;
  124.      scn_pos( &sc , 22 , 0 )  ;
  125.      scn_ws(  " END   = Last  Page      " , & sc )  ;
  126.      sprintf(s,    "  %c   = Next Line       ",DN_A)  ;
  127.      scn_ws( s , & sc )  ;
  128.      scn_ws(     "PG DN = Next Page " , & sc )  ;
  129.      scn_pos( &sc , 23 , 0 ) ;
  130.      scn_ws(  " ESC   = Exit Pgm        " , & sc )  ;
  131.      scn_ws(     "SPACE = Move to position " , &sc )  ;
  132.      scn_pos( &sc , 24 , 0 )  ;
  133.      vid_set_cur( 24 , 0 )  ;
  134.   }
  135.  
  136.  
  137. int  init_disp()
  138.   {
  139.      scn_init(&sc)  ;
  140.   }
  141.  
  142.  
  143.